// src/entity/SensorHourlyData.ts
import { Entity, PrimaryColumn, Column, Index, JoinColumn, ManyToOne } from 'typeorm';
import { Device } from './Device';

@Entity({ name: 'sensor_hourly_data' })
@Index('idx_sensor_hourly_time', ['hourStart'])
export class SensorHourlyData {
  @PrimaryColumn()
  deviceId!: string;

  @PrimaryColumn()
  metricType!: string; // 'temperature', 'humidity', 'pm25'

  @PrimaryColumn({ type: 'timestamp' })
  hourStart!: Date;

  @Column('float')
  metricValue!: number;

  @ManyToOne(() => Device, device => device.did, {
    onDelete: 'CASCADE' // 若设备被删，级联删除其数据
  })
  @JoinColumn({ name: 'deviceId' })
  device!: Device;
}
